const tree = {
    "id": "a",
    "children": [
        {
            "id": "b",
            "children": [
                {
                    "id": "c",
                    "children": [
                        {
                            "id": "d",
                            "children": []
                        }
                    ]
                }
            ]
        },
        {
            "id": "e",
            "children": []
        }
    ]
};


const getTree=(tree={})=>{
    let ret;
    let id=tree.id,children=tree.children||[];
    ret={id,children:children.map(getTree)};
    return ret;
};

console.log(JSON.stringify(getTree(tree),null,2));
